using System;
using System.Collections;
using UnityEngine;

public class TriviaButton : MonoBehaviour
{
	public delegate void OnClickDelegate(int answerIndex, TriviaButton button);

	protected OnClickDelegate onComplete;

	protected Action onCompleteText;

	public UISprite buttonSprite;

	public UILabel buttonLabel;

	protected int answerIndex;

	public void Hide()
	{
		base.gameObject.SetActive(false);
	}

	public void ShowText(string text, Action onCompleteText)
	{
		onComplete = null;
		buttonLabel.text = text;
		buttonSprite.spriteName = "btn-blue";
		this.onCompleteText = onCompleteText;
		base.gameObject.SetActive(true);
	}

	public void ShowAnswer(string answer, int answerIndex, OnClickDelegate onComplete)
	{
		base.gameObject.SetActive(true);
		buttonLabel.text = answer;
		this.answerIndex = answerIndex;
		buttonSprite.spriteName = "btn-blue";
		this.onComplete = onComplete;
		onCompleteText = null;
		StopAllCoroutines();
	}

	public void OnClick()
	{
		if (onCompleteText != null)
		{
			onCompleteText();
		}
		else if (onComplete != null)
		{
			onComplete(answerIndex, this);
		}
	}

	public void ShowAnswerAnim(bool trueAnswer, Action onComplete)
	{
		StopAllCoroutines();
		StartCoroutine(DoShowAnswer(trueAnswer, onComplete));
	}

	private IEnumerator DoShowAnswer(bool trueAnswer, Action onComplete)
	{
		for (int i = 0; i < 2; i++)
		{
			buttonSprite.spriteName = ((!trueAnswer) ? "btn-red" : "btn-green");
			yield return new WaitForSeconds(0.1f);
			buttonSprite.spriteName = "btn-blue";
			yield return new WaitForSeconds(0.1f);
		}
		buttonSprite.spriteName = ((!trueAnswer) ? "btn-red" : "btn-green");
		yield return new WaitForSeconds(0.5f);
		if (onComplete != null)
		{
			onComplete();
		}
	}
}
